<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        // <!-- 封装思想，把不变的隔离出来，把变化的封装起来 -->
        var makeSound = function (animal) {
            animal.sound()
        }

        var Duck = function () { }
        Duck.prototype.sound = function () {
            console.log('嘎嘎嘎');
        }
        var Chicken = function () { }
        Chicken.prototype.sound = function () {
            console.log('咯咯咯');
        }

        makeSound(new Duck())
        makeSound(new Chicken())

        var Dog = function(){}
        Dog.prototype.sound = function(){
            console.log('汪汪汪');
        }
        makeSound(new Dog())
    </script>

    <!-- 封裝 -->
    <script>
        var myObj = (function(){
            var __name = 'seven';
            return{
                getName:function(){
                    return __name;
                }
            }
        })();

        console.log(myObj.getName()); //seven
        console.log(myObj.__name); // undefiend


    </script>


</body>

</html>